package com.totcy.atom.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.totcy.atom.R;
import com.totcy.atom.bean.GankTypeBean;
import com.totcy.atom.utils.glide.GlideUtil;
import com.totcy.baselibrary.adapter.BaseLoadMoreAdapter;
import com.totcy.baselibrary.adapter.BaseViewHolder;
import com.totcy.baselibrary.utils.DisplayUtil;
import com.totcy.baselibrary.utils.ScreenUtil;

import java.util.List;

/**
 * description: 图片列表适配器
 * author: Totcy
 * date: 2017/11/2 14:41
 * update: 2017/11/2
 */

public class GankImageListAdapter extends BaseLoadMoreAdapter<GankTypeBean, BaseViewHolder, BaseViewHolder> {

    private int width = 0;
    private int height = 0;

    public GankImageListAdapter(Context mContext, List<GankTypeBean> mDatas) {
        super(mContext, mDatas);
        width = ScreenUtil.getScreenWidth(mContext);
        height = DisplayUtil.dip2px(mContext, 300);
    }

    @Override
    protected BaseViewHolder onCreateItemViewHolder(ViewGroup parent, int viewType) {
        return new BaseViewHolder(getItemView(R.layout.item_image, parent));
    }

    @Override
    protected void onBindItemViewHolder(BaseViewHolder holder, int position) {
        //gank 的图片都在七牛上，帮助节省流量，取需要的尺寸。
        // ?imageView2/0/w/100
        GankTypeBean imageBean = mDatas.get(position);
        String url = imageBean.getUrl() + "?imageView2/0/w/"+width+"/h/"+height;

        ImageView ivGirl = holder.getView(R.id.iv_girl);
        GlideUtil.loadImage(mContext,url,ivGirl);

        holder.setText(R.id.tv_desc, imageBean.getDesc());
    }

    @Override
    public boolean hasHeader() {
        return false;
    }

    @Override
    protected BaseViewHolder onCreateHeaderViewHolder(ViewGroup parent, int viewType) {
        return null;
    }

    @Override
    protected void onBindHeaderViewHolder(BaseViewHolder holder) {

    }
}
